package com.alibaba.spider.service.impl;

import com.alibaba.spider.service.CrawlService;
import com.alibaba.spider.util.JsoupHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/10/4 5:31 下午
 */
@Slf4j
@Service
public class CrawlServiceImpl implements CrawlService {
    @Override
    public List<String> getResult(String url) {
        List<String> strList = new ArrayList<>();
        String result = JsoupHelper.getContent(url, "//meta[2]/@content");
        if (result == null) {
            return strList;
        }
        String regex = ",";
        for (String str : result.split(regex)) {
            strList.add(str.trim());
        }
        return strList;
    }

    public static void main(String[] args) {
        CrawlServiceImpl s = new CrawlServiceImpl();
        List<String> list = s.getResult("https://www.alibaba.com/product-detail/OEM-Customized-2019-Printed-Tropical-Floral_62084397812.html?spm=a2700.galleryofferlist.normalList.1.22b16ff2lxR4py&s=p");
        for (String s1 : list) {
            System.out.println(s1.trim());
        }
    }
}
